﻿using ElectronicWMSA.Comm.ClassFiles;
using ElectronicWMSA.Comm.Forms.Message;
using System;
using System.Windows.Forms;
using WMSADBUtility;

namespace ElectronicWMSA.List.Second
{
    public partial class UPS_Change : Form
    {
        string Nid = "";
        string Tracking_no = "";
        string Model_no = "";
        string Serial_no = "";
        string City = "";

        public UPS_Change(string nid,string tracking_no,string model_no,string serial_no,string city)
        {
            InitializeComponent();
            Nid = nid;
            Tracking_no = tracking_no;
            Model_no = model_no;
            Serial_no = serial_no;
            City = city;
            GetValues();
        }

        #region 按钮：退出
        private void bt_Cancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        #endregion

        #region 按钮：确定
        private void bt_confirm_Click(object sender, EventArgs e)
        {

                if (MessageClass.enquire("确认编辑选中数据？") == DialogResult.OK)
                {
                if (tb_Tracking_No.Text == "" || tb_Model_No.Text == "" || tb_Serial_No.Text == "" || tb_City.Text == "")
                {
                    MessageClass.error("输入框不能有空");
                    return;
                }
                else if (ValidationRegex.VadidateDataLetter(tb_Tracking_No.Text) == false)
                {
                    MessageClass.error("Tracking_No框输入不规范，只能输入字母和数字");
                    return;
                }
                else if (ValidationRegex.VadidateDataLetter01(tb_Model_No.Text) == false)
                {
                    MessageClass.error("Model_No框输入不规范，只能输入字母和数字以及-");
                    return;
                }
                else if (ValidationRegex.VadidateDataLetter(tb_Serial_No.Text) == false)
                {
                    MessageClass.error("Serial_No框输入不规范，只能输入字母和数字");
                    return;
                }
                else if (ValidationRegex.CapitallettersAndSpaces(tb_City.Text) == false)
                {
                    MessageClass.error("City框输入不规范，只能输入大写字母和空格");
                    return;
                }



                string query = "update [T_UPS_Excel_Manage] set " +
                                   "Tracking_No='" + tb_Tracking_No.Text + "', " +
                                   "Model_No= '" + tb_Model_No.Text + "', " +
                                   "Serial_No= '" + tb_Serial_No.Text + "', " +
                                   "City= '" + tb_City.Text + "', " +
                                   "Modify_Time= '" + DateTime.Now + "' " +
                                   "where nid =" + Nid + "";
                    int result = DBHelper.ExecuteSql(query);
                

                    if (result > 0)
                    {
                        MessageClass.right("信息更新成功");
                    SystemVariable.AddLogInfo("数据修改", "操作员：【" + SystemVariable.Login_Name + "】对表内数据进行了修改");
                    }
                }

            this.Close();
        }
        #endregion

        public void GetValues()
        {
            tb_Tracking_No.Text = Tracking_no;
            tb_Model_No.Text = Model_no;
            tb_Serial_No.Text = Serial_no;
            tb_City.Text = City;
        }
    }
}
